﻿/*==============================================================
 * ArticleCateModel.cs
 * Copyright (C) 2014 贵州惠众互联 Inc. All rights reserved.
 *==============================================================
 * Author:   罗应红
 * Date:     2014/03/03 11:14:17.
 * Version:  1.0
 * QQ:		 88962800
*==============================================================*/

using System.Collections.Generic;
using System.Linq;
using QDT.Core.Domain;
using QDT.Core.Domain.Enums;

namespace QDT.Web.Admin.Models {
    public class ArticleCateModel {
        public ArticleCateModel() {
            Child = new List<ArticleCateModel>();
        }

        public ArticleCateModel(ArticleCate articleCate) {
            Id = articleCate.ID;
            Title = articleCate.Title;
            Brief = articleCate.Brief;
            ParentId = articleCate.ParentId;
            IsEffect = articleCate.IsEffect;
            IsDelete = articleCate.IsDelete;
            TypeId = articleCate.InnerArticleTypeId;
            Sort = articleCate.Sort;
            Child = new List<ArticleCateModel>();
        }

        public int Id { set; get; }
        /// <summary>
        /// 标题
        /// </summary>
        public string Title { set; get; }
        /// <summary>
        /// 简单描述
        /// </summary>
        public string Brief { set; get; }
        /// <summary>
        /// 父Id
        /// </summary>
        public int? ParentId { set; get; }
        /// <summary>
        /// 是否有效
        /// </summary>
        public bool IsEffect { set; get; }
        /// <summary>
        /// 是否已删除
        /// </summary>
        public bool IsDelete { set; get; }

        /// <summary>
        /// 类型Id
        /// <remarks>
        ///     
        /// </remarks>
        /// </summary>
        public int TypeId { set; get; }

        /// <summary>
        /// 排序
        /// </summary>
        public int Sort { set; get; }
        /// <summary>
        /// 子分类
        /// </summary>
        public IList<ArticleCateModel> Child { set; get; }
        public bool HasChild{get { return Child.Any(); }}

        public ArticleCate ToEntity() {
            return new ArticleCate {
                Brief = Brief,
                Title = Title,
                IsEffect = IsEffect,
                ID = Id,
                Child = null,
                Sort = Sort,
                IsDelete = IsDelete,
                Parent =  null,
                ParentId = ParentId == 0 ? null : ParentId,
                TypeId = (ArticleType)TypeId
            };
        }
    }
}